﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BalanceCenter_Net : PageBase
{
    public string[] MemberBack = new string[7];
    public string[] NextID = new string[7];
    public string ParentStr = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        long id = Shove._Convert.StrToLong(this.Request["id"], -1);
        if (id < 0)
        {
            id = _Customer.ID;
        }

        if (id < _Customer.ID)
        {
            PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读写错误", this.GetType().BaseType.FullName);

            return;
        }

        BindData(id);
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        isAtFramePageLogin = true;                              //是框架页
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        //RequestCompetences = Competences.BuildCompetencesList(Competences.Net);

        base.OnLoad(e);
    }

    #endregion

    private void BindData(long id)
    {
        DataSet ds = new DataSet();
        DAL.Procedures.P_GetNet(ref ds, id);

        if (ds == null)
        {
            PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读写错误", this.GetType().BaseType.FullName);

            return;
        }

        if (ds.Tables.Count == 0)
        {
            PublicFunction.GoError(ErrorNumber.NoData, "暂无数据", this.GetType().BaseType.FullName);

            return;
        }

        DataTable dt = ds.Tables[0];

        if (dt.Columns.Count == 0)
        {
            PublicFunction.GoError(ErrorNumber.NoData, "暂无数据", this.GetType().BaseType.FullName);

            return;
        }

        for (int i = 0; i < 7; i++)
        {
            DataRow[] dr = dt.Select("Locate=" + (i + 1).ToString());
            if (dr.Length < 1)
            {
                MemberBack[i] = "#FFFFFF";
            }
            else
            {
                ((Panel)this.FindControl("Panel" + (i + 1).ToString())).Visible = true;

                long UserID = Shove._Convert.StrToLong(dr[0]["id"].ToString(), -1);
                if (UserID == -1)
                {
                    MemberBack[i] = "#FFFFFF";
                    ((Label)this.FindControl("labName" + (i + 1).ToString())).Text = "<a class='li8' href='Buy.aspx?PID=" + dr[0]["ParentID"].ToString() + "&LR=" + dr[0]["Location"].ToString() + "'>空位推荐</a>";
                }
                else
                {
                    string strCustomerType = "";
                    int CustomerTypeID = Shove._Convert.StrToInt(dr[0]["CustomerTypeID"].ToString(), 1);
                    bool isActivation = Shove._Convert.StrToBool(dr[0]["isActivation"].ToString(), false);

                    if (isActivation)
                    {
                        if (CustomerTypeID == 1)
                        {
                            MemberBack[i] = "#fad6d8";
                            strCustomerType = "加盟店";
                        }
                    }
                    else
                    {
                        MemberBack[i] = "#f8f7c9";
                    }

                    ((Label)this.FindControl("labBDZX" + (i + 1).ToString())).Text = "<a class='li8' href='Net.aspx?id=" + dr[0]["id"].ToString() + "'>" + dr[0]["CustomerNo"].ToString() + "</a>";
                    ((Label)this.FindControl("labName" + (i + 1).ToString())).Text = strCustomerType;

                    long L = 0;
                    long R = 0;
                    long L_CurrentMonth = 0;
                    long R_CurrentMonth = 0;
                    long L_CurrentDay = 0;
                    long R_CurrentDay = 0;
                    int L_Residual = 0;
                    int R_Residual = 0;

                    if (DAL.Procedures.P_GetScoreForCustomer(Shove._Convert.StrToLong(dr[0]["id"].ToString(), -1), ref L, ref R, ref L_CurrentMonth, ref R_CurrentMonth, ref L_CurrentDay, ref R_CurrentDay, ref L_Residual, ref R_Residual) < 0)
                    {
                        ((Label)this.FindControl("labSL" + (i + 1).ToString())).Text = "0";
                        ((Label)this.FindControl("labSR" + (i + 1).ToString())).Text = "0";
                        ((Label)this.FindControl("labSL" + (i + 1).ToString() + "_1")).Text = "0";
                        ((Label)this.FindControl("labSR" + (i + 1).ToString() + "_1")).Text = "0";
                        ((Label)this.FindControl("labSL" + (i + 1).ToString() + "_2")).Text = "0";
                        ((Label)this.FindControl("labSR" + (i + 1).ToString() + "_2")).Text = "0";
                        ((Label)this.FindControl("labSL" + (i + 1).ToString() + "_3")).Text = "0";
                        ((Label)this.FindControl("labSR" + (i + 1).ToString() + "_3")).Text = "0";
                    }
                    else
                    {
                        ((Label)this.FindControl("labSL" + (i + 1).ToString())).Text = L.ToString();
                        ((Label)this.FindControl("labSR" + (i + 1).ToString())).Text = R.ToString();
                        ((Label)this.FindControl("labSL" + (i + 1).ToString() + "_1")).Text = L_CurrentMonth.ToString();
                        ((Label)this.FindControl("labSR" + (i + 1).ToString() + "_1")).Text = R_CurrentMonth.ToString();
                        ((Label)this.FindControl("labSL" + (i + 1).ToString() + "_2")).Text = L_CurrentDay.ToString();
                        ((Label)this.FindControl("labSR" + (i + 1).ToString() + "_2")).Text = R_CurrentDay.ToString();
                        ((Label)this.FindControl("labSL" + (i + 1).ToString() + "_3")).Text = L_Residual.ToString();
                        ((Label)this.FindControl("labSR" + (i + 1).ToString() + "_3")).Text = R_Residual.ToString();
                    }
                }

                if (i >= 3)
                {
                    if (Shove._Convert.StrToBool(dr[0]["HasSub"].ToString(), false))
                    {
                        NextID[i] = dr[0]["id"].ToString();
                        ((System.Web.UI.WebControls.Image)this.FindControl("imgNext" + (i + 1).ToString())).Visible = true;
                    }
                }
            }
        }
    }

    protected void btnSerch_Click(object sender, EventArgs e)
    {
        if (this.tbSerchUserName.Text.Trim().Equals(""))
        {
            Shove._Web.JavaScript.Alert(this, "请输入要搜索的关键字");

            return;
        }

        string Return = "";
        int Result = 0;

        Customer Customer = new Customer(_Site.ID);
        Customer.CustomerNO = tbSerchUserName.Text.Trim();
        Result = Customer.GetCustomerInformationByNO(ref Return);

        if (Result != 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, "搜索的会员ID不存在。");

            return;
        }

        this.Response.Redirect("Net.aspx?id=" + Customer.ID);
    }
}